<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <link rel="stylesheet" href="http://localhost:3200/css/index.css">
</head>

<body>
    帐号：<input type="text" name="" id="account"><br>
    密码：<input type="password" name="" id="password"><br>
    <button onclick="login()">登陆</button>
    <button onclick="register()">注册</button>
</body>
<script>
    const account = document.querySelector('#account')
    const password = document.querySelector('#password')
    function register(){
        window.location.href="http://localhost:3200/register.html"
    }
    function login() {
        fetch('http://localhost:3200/api/user/login', {
            method: 'POST',
            body: JSON.stringify({ account: account.value, password: password.value }),
            headers: {
                'content-type': "application/json"
            }
        }).then(res => res.json()).then(res => {
            console.log(res);
            if (res.code !== 200) {
                alert('帐号或密码错误')
            } else {
                alert('登陆成功')
                setTimeout(()=>{
                    window.location="http://localhost:3200/home";
                },1000)
            }
        })
    }
</script>

</html>